package exception;

import java.io.FileOutputStream;
import java.io.IOException;

public class FinallyDemo2 {//异常处理机制在io流中的运用
    public static void main(String[] args) {
        System.out.println("程序开始了");
        FileOutputStream fos =null;
        try{
            fos =new FileOutputStream("fos.dat");
            fos.write(1);
        }catch(IOException e){
            System.out.println("出现IO异常并解决了");
        }finally{
            try {
                fos.close();
            } catch (IOException e) {
                System.out.println("关闭时出现异常并解决了");//程序正常则跳过catch
            }
        }
        System.out.println("程序结束了");
    }
}
